package com.wjc.controller;

import com.wjc.pojo.User;
import com.wjc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class UserController {


    @Autowired
    @Qualifier("UserServiceImpl")
    private UserService userService;

    @RequestMapping("/login")
    public String login(User user, HttpSession session) throws Exception{
        user = userService.checkLogin(user.getUsername(), user.getPassword());
        if(user!=null){
            //HttpSssion是设置session的关键，
            // 后面通过session.setAttribute()设置session，
            // 这也是在上文中提到的需要session的部分。在后来的注销中可以使用session.invalidate。
            session.setAttribute("user",user);
            return "welcome";
        }
         return "fail";
    }

    @RequestMapping("/register")
    public String toRegister() {
        return "register";
    }

    @RequestMapping("/forget")
    public String toForget() {
        return "forget";
    }


}
